package asynctwitfiltered;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class BadwordFilter {
	
	private String badwords[];
	
	private String[] bannedWords = {"porra","puta","caralho","buceta","boceta",
									"pica","rola","pora","put@","bucet@","bocet@",
									"carai","caraio","caray","pau","pomba","cu",
									"poha","poota","p0rra","penis","pênis",
									"vagina","vulva","jeba","pulta","c@ralho",
									"c@r@lho","car@lho","caralhu","c@rai","car@i",
									"c@r@i","cacete","c@cete","casete","pika",
									"pyca","pyka","karalho","karai","karaio", "sexo",
									"k@rai","kar@i","k@r@i","grelo","grelinho",
									"pinguelo","cuzinho","cuzao","cuz�o","cuz@o",
									"anus","ânus","vadia","safada","safado","escroto",
									"escrota","puto","putaria","bucetuda","caralhudo",
									"ladrão","ladrao","roubo","rouba","pentelho","pentei",
									"prostituta","meretriz","viado","veado","vyado",
									"ve@do","gay","sapatao","sapatão","sapata","gordo",
									"gorda","escrotagem","vi@do","ku","kct","kacete",
									"kacet","gozada","gala","gozo","goza","anal",
									"drogas","maconha","cocaina","coca�na","crack",
									"lsd","ecstasy","hemp","marijuana", "merda",
									"baitola","boiola","boyola","tabacudo","punheta",
									"siririca","cunheta","ciririca","ponheta"};
	
	private String[] bannedNames = {"dilma","fernando","paulo", "lula", "luiz",
									"maluf","skaf","rousseff","silva","kassab",
									"alckmin","serra","cardoso","erundina","freire",
									"barreto","coelho","batista","rodrigues","alves",
									"henrique","collor","cunha","coutinho","couto",
									"lima","sarney","luis","inacio","in�cio", "hitler",
									"vargas","mello","melo","suplicy","mussolini"};
	
	private ArrayList<String> bannedWordsList;
	private ArrayList<String> bannedNamesList;
	private ArrayList<String> badwordsList;
	
	private String fileName = "BADWORDS.txt";
	
	private void loadBadwords() {
		try {
		    StringBuffer sb = new StringBuffer();
		    String line;
		    
			BufferedReader reader = new BufferedReader(
					new FileReader(new File(fileName)));

			while((line = reader.readLine())!= null) {
		        sb.append(line);
		    }

		    badwords = sb.toString().split(",");
		    
		    reader.close();
			
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public BadwordFilter(boolean loadFile) {
		if (loadFile) {
			loadBadwords();
			badwordsList = new ArrayList<String>(Arrays.asList(badwords));
		}
		bannedWordsList = new ArrayList<String>(Arrays.asList(bannedWords));
		bannedNamesList = new ArrayList<String>(Arrays.asList(bannedNames));
	}
	
	public BadwordFilter(String bfile) {
		if (bfile.length()>0) {
			fileName = bfile;
			loadBadwords();
			badwordsList = new ArrayList<String>(Arrays.asList(badwords));
		}
		bannedWordsList = new ArrayList<String>(Arrays.asList(bannedWords));
		bannedNamesList = new ArrayList<String>(Arrays.asList(bannedNames));
	}
	
	public BadwordFilter() {
		bannedWordsList = new ArrayList<String>(Arrays.asList(bannedWords));
		bannedNamesList = new ArrayList<String>(Arrays.asList(bannedNames));		
	}
	
	public synchronized void reloadBadwords() {
		loadBadwords();
	}
	
	public String[] getBannedWords() {
		return bannedWords;
	}
	
	public String[] getBannedNames() {
		return bannedNames;
	}
	
	public String[] getBadWords() {
		return badwords;
	}
	
	public boolean isBannedWord(String s) {
		return bannedWordsList.contains(s.toLowerCase());
	}
	
	public boolean isBannedName(String s) {	
		return bannedNamesList.contains(s.toLowerCase());
	}
	
	public boolean isBadWord(String s) {
		if (badwordsList != null) {
			return badwordsList.contains(s.toLowerCase());
		} else {
			return false;
		}
	}


}
